/*************************
新增编辑机构类
* */
<template>
  <div>
    <el-dialog
      :title="dialogTitle"
      :close-on-click-modal="false"
      :visible.sync="visible"
      top="8vh"
      @close="closeDialog()"
    >
      <el-form
        :model="dataForm"
        :rules="dataRule"
        ref="dataForm"
        @keyup.enter.native="dataFormSubmit()"
        label-width="130px"
      >
        <div class="boxsty">
          <el-row>
            <el-col>
              <el-form-item label="分类:" prop="fl">
                <el-input v-model="dataForm.fl" placeholder="分类" clearable max-length="20"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col>
              <el-form-item label="依据:" prop="yj">
                <el-input type="textarea" :rows="4" v-model="dataForm.yj" placeholder="依据"  max-length="10"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="指标规则:" prop="zbgz">
                <el-select
                  v-model="dataForm.zbgz"
                  placeholder="请选择指标规则"
                  class="xiaLa"
                  style="width: 100%"
                  :clearable="true"
                  @change="selecteRefresh"
                >
                  <el-option
                    v-for="(item, index) in zbgzsList"
                    :key="index"
                    :label="item.name"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
             <!-- <el-form-item label="指标规则:" prop="zbgz">
                <el-input v-model="dataForm.zbgz" placeholder="指标规则" clearable max-length="10"></el-input>
              </el-form-item>-->
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="加扣分标准:" prop="jkfbz">
                <el-input v-model="dataForm.jkfbz" placeholder="加扣分标准" clearable max-length="10"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button v-loading="isSubmit" type="primary" plain @click="saveFormData">确定</el-button>
        <el-button type="primary" plain @click="closeDialog()">返回</el-button>

      </span>
    </el-dialog>

  </div>
</template>

<script>
    import {
        addUserDepot,
        updateUserDepot,
    } from "@/api/dailyExamine/eventExamine/event.js";

    export default {
        components: {

        },
        props: {
            dialogTitle: String
        },
        data() {

            var checkFl= (rule, value, callback) => {
                if (value) {
                    if (value.length>20) {
                        callback("最多可输入20个字符!");
                    } else {
                        callback();
                    }
                } else {
                    callback("请输入分类");
                }
            };

            var checkYj = (rule, value, callback) => {
                if (value) {
                    if (value.length>250) {
                        callback("最多可输入250个字符!");
                    } else {
                        callback();
                    }
                } else {
                    callback("请输入依据");
                }
            };

            return {
                isSubmit: false, //保存按钮的loading
                mainDept: [], //部门数组
                deletePerson: [], //删除人员数组
                deleteForm: {}, //删除弹窗中的删除人员对象
                deleteFormVisible: false, //删除弹窗显隐
                usercomment: false, //人员选择显隐
                usercommentLd: false, //人员选择显隐
                fakeData: [], //空数组
                multipleSelection: [], //选中的参与人
                zxgzCyrxxList: [], //参与人数组
                visible: false, //最外弹窗显隐
                //canSubmit: false,
                dataForm: {},
                qcJlId: "",
                qcJlRealName: "",
                innerVisible: false,
                fileListUpload: [],
                limitUpload: 3,
                accountList: [],

                zbgzsList: [
                    { name: "正指标", value: "0" },
                    { name: "负指标", value: "1" },
                ],
                dataRule: {
                    fl: [
                        { required: true, trigger: "blur",validator: checkFl}
                    ],
                    yj: [
                        { required: true, trigger: "blur",validator:checkYj}
                    ]
                }
            };
        },
        watch: {},
        created() {

        },
        methods: {
            //初始化
            csh() {
                this.dataForm = {};
            },
            init(obj) {
                if (obj) {
                    this.dataForm = obj;

                }else{
                    this.dataForm.zbgz = "1";
                }
                this.visible = true;
                //this.canSubmit = true;
            },
            selecteRefresh(obj){
              this.$forceUpdate()
            },
            saveFormData() {
                this.isSubmit = true;
                this.dataForm["yjkfl"]='jg';
                this.$refs["dataForm"].validate(valid => {
                    if (valid) {
                        // 编辑
                        if (this.dataForm.id) {
                            //debugger;
                            updateUserDepot(this.dataForm).then(r => {
                                if (r.data.code == 0) {
                                    this.isSubmit = false;
                                    this.$emit("refreshDataList");
                                    this.closeDialog();
                                    this.$message.success("编辑成功");
                                }
                            });
                        } else {
                            // 新增
                            addUserDepot(this.dataForm).then(r => {
                                if (r.data.code == 0) {
                                    this.isSubmit = false;
                                    this.$emit("refreshDataList");
                                    this.closeDialog();
                                    this.$message.success("新增成功");
                                }
                            });
                        }
                    } else {
                        return false;
                    }
                });
            },
            closeDialog() {
                this.visible = false;
                this.$emit("closeDialog");
            }
        }
    };
</script>
<style lang="scss" scoped>
  /deep/.el-table__header-wrapper .el-checkbox {
    display: block!important;
  }
  .xiaLaTwo .el-input--small .el-input__inner {
    border: none;
    background: transparent;
  }
  .xiaLaTwo .el-icon-arrow-up:before {
    content: "";
  }
  .el-divider {
    background-color: #fff;
  }
  .tree-box {
    height: 500px;
    overflow: auto;
  }
  .inputDeep{
    border: 0;
  }
</style>
